package com.lxq.www.aspect;

import com.lxq.www.aspect.dao.ArticleServiceLogDao;
import com.lxq.www.aspect.logentities.ArticleServiceLog;
import org.aspectj.lang.JoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

//@Aspect
@Component
public class ArticleServiceAspect {

    @Autowired
    private ArticleServiceLogDao serviceLogDao;

    //@Pointcut(value = "execution(* www.service.ArticleService.*(..))")
    //@Pointcut(value = "execution(* com.lxq.www.service.ArticleService.*(..))\")")
    public void serviceMethod(){
        System.out.println("serviceMethod方法执行");
    }

    //@Before(value = "serviceMethod()")
    public void beforeMethod(JoinPoint joinPoint){
        ArticleServiceLog log=new ArticleServiceLog();
        log.setMethodName(joinPoint.getSignature().getName());
        log.setOccured(new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").format(new Date()));
        log.setLogText("args="+ Arrays.toString(joinPoint.getArgs()));
        System.out.println(log.toString());
        serviceLogDao.save(log);
    }

//    @After(value = "serviceMethod()")
//    public void afterMethod(JoinPoint joinPoint){
//        System.out.println("afterMethod方法执行："+joinPoint.getKind());
//    }

}
